/*******************************************************************************
 * Copyright 2011 WaTho
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *   http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 ******************************************************************************/
package de.wathoserver.android.dragoid.api;

import de.wathoserver.android.dragoid.api.StockItem.STOCK_TYPE;

/**
 * Material, das ein Gebäude benötigt.
 * 
 * @author watho
 * 
 */
public class BuildingMaterial {

	public static final String BUILDING_MATERIAL_NEEDS = "building_material_needs";
	public static final String BUILDING_MATERIAL_HAS = "building_material_has";
	public static final String BUILDING_MATERIAL_VALUE = "building_material_value";
	public static final String BUILDING_MATERIAL_STOCKTYPE = "building_material_stocktype";

	int needs;
	int has;
	int value;
	STOCK_TYPE stockType;

	public void setNeeds(int needs) {
		this.needs = needs;
	}

	/**
	 * Menge der benötigten Ware pro Stunde
	 * 
	 * @return
	 */
	public int getNeeds() {
		return needs;
	}

	/**
	 * Menge der bereitgestellten Ware
	 * 
	 * @param has
	 */
	public void setHas(int has) {
		this.has = has;
	}

	/**
	 * Menge der bereitgestellten Ware
	 * 
	 * @return
	 */
	public int getHas() {
		return has;
	}

	public void setValue(int value) {
		this.value = value;
	}

	public int getValue() {
		return value;
	}

	public void setStockType(STOCK_TYPE stockType) {
		this.stockType = stockType;
	}

	public STOCK_TYPE getStockType() {
		return stockType;
	}

	public void setStockType(String stocktypename) {
		try {
			// Log.d(MainActivity.LOG_TAG, stocktypename);
			this.stockType = STOCK_TYPE.valueOf(stocktypename.toUpperCase());
		} catch (IllegalArgumentException e) {
		} catch (NullPointerException e) {
		}
	}

	/**
	 * Gibt die Menge an Waren zurück, die für eine Aufstockung auf 24h
	 * gebraucht werden.
	 * 
	 * @return
	 */
	public int getInc24() {
		return getIncHours(24);
	}

	/**
	 * Gibt die Menge an Waren zurück, die für eine Aufstockung auf
	 * <code>hours</code> Stunden benötigt wird.
	 * 
	 * @param hours
	 * @return
	 */
	public int getIncHours(int hours) {
		return Math.max(0, (needs * hours) - has);
	}

	// public Map<String, String> toMap() {
	// Map<String, String> result = new HashMap<String, String>();
	// result.put(BUILDING_MATERIAL_HAS, has);
	// result.put(BUILDING_MATERIAL_NEEDS, needs);
	// result.put(BUILDING_MATERIAL_VALUE, String.valueOf(value));
	// result.put(BUILDING_MATERIAL_STOCKTYPE, stockType.name().toLowerCase());
	// return result;
	// }

}
